package com.isoftstone.controller;
import com.isoftstone.pojo.Occupancy;
import com.isoftstone.pojo.PageResult;
import com.isoftstone.pojo.dto.AssignDormitoryDTO;
import com.isoftstone.pojo.dto.OccupancyQueryDTO;
import com.isoftstone.service.OccupancyService;
import com.isoftstone.util.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author :W.
 * @Date:2025/9/15 15:29
 */
@RestController
@RequestMapping("/occupancy")
public class OccupancyController {
    @Autowired
    private OccupancyService occupancyService;
    /**
     * 分配宿舍
     */
   /**
     * 多条件查询入住记录
     */

   @GetMapping("/query")
   public Result<PageResult<Occupancy>> queryByConditions(OccupancyQueryDTO queryDTO) {
       return occupancyService.queryByConditions(queryDTO);
   }
    /**
     * 分配宿舍
     */
    @PostMapping("/assign")
    public Result<?> assignDormitory(@Valid @RequestBody AssignDormitoryDTO dto) {
        return occupancyService.assignDormitory(dto);
    }

    /**
     * 调换宿舍
     */
    @PostMapping("/change")
    public Result<?> changeDormitory(@Valid @RequestBody AssignDormitoryDTO dto) {
        return occupancyService.changeDormitory(dto);
    }

    /**
     * 单个退宿
     */
    @PostMapping("/checkout/{id}")
    public Result<?> checkOut(@PathVariable Integer id) {
        return occupancyService.checkOut(id);
    }

    /**
     * 批量退宿
     */
    @PostMapping("/batch-checkout")
    public Result<?> batchCheckOut(@RequestBody List<Integer> ids) {
        return occupancyService.batchCheckOut(ids);
    }

    /**
     * 获取入住信息列表
     */
    @GetMapping("/list")
    public Result<?> getOccupancyList() {
        return occupancyService.getOccupancyList();
    }
    /**
     * 删除入住记录（支持批量）
     */
    @DeleteMapping("/delete")
    public Result<?> deleteRecords(@RequestBody List<Integer> ids) {
        return occupancyService.deleteRecords(ids);
    }


    @GetMapping("/check-current/{studentNumber}") // 正确路径
    public Result<?> checkCurrentOccupancy(@PathVariable String studentNumber) {
        return occupancyService.checkCurrentOccupancy(studentNumber);
    }


}
